package avicit.bdp.dds.dao.entity;

import avicit.bdp.common.base.BaseDTO;
import avicit.platform6.core.annotation.log.FieldRemark;
import avicit.platform6.core.annotation.log.Id;
import avicit.platform6.core.annotation.log.LogField;
import avicit.platform6.core.properties.PlatformConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Objects;

/**
 * udf function
 */
@ApiModel(value = "UdfFunc", description = "bdp_dds_udfs")
@Table(name = "bdp_dds_udfs")
public class UdfFunc extends BaseDTO {

    @Id
    @LogField
    @ApiModelProperty(value = "id", name = "id")
    @FieldRemark(column = "id", field = "id", name = "主键")
    @javax.persistence.Id
    @Column(name = "id")
    private String id;

    @LogField
    @ApiModelProperty(value = "资源名称", name = "name")
    @FieldRemark(column = "name", field = "name", name = "资源名称")
    @Column(name = "name")
    private String name;

    @LogField
    @ApiModelProperty(value = "函数名称", name = "funcName")
    @FieldRemark(column = "func_name", field = "funcName", name = "函数名称")
    @Column(name = "func_name")
    private String funcName;

    @LogField
    @ApiModelProperty(value = "类名称", name = "className")
    @FieldRemark(column = "class_name", field = "className", name = "类名称")
    @Column(name = "class_name")
    private String className;

    @LogField
    @ApiModelProperty(value = "项目Id", name = "projectId")
    @FieldRemark(column = "project_id", field = "projectId", name = "项目Id")
    @Column(name = "project_id")
    private String projectId;

    @LogField
    @ApiModelProperty(value = "类型：0--hiveUDF；1--sparkUDF", name = "type")
    @FieldRemark(column = "type", field = "type", name = "类型")
    @Column(name = "type")
    private Integer type;

    @LogField
    @ApiModelProperty(value = "参数名", name = "argTypes")
    @FieldRemark(column = "arg_types", field = "argTypes", name = "参数名")
    @Column(name = "arg_types")
    private String argTypes;

    @LogField
    @ApiModelProperty(value = "分类ID", name = "typeId")
    @FieldRemark(column = "type_id", field = "typeId", name = "分类ID")
    @Column(name = "type_id")
    private String typeId;

    @LogField
    @ApiModelProperty(value = "备注", name = "remark")
    @FieldRemark(column = "remark", field = "remark", name = "备注")
    @Column(name = "remark")
    private String remark;

    //@LogField
    @ApiModelProperty(value = "资源id", name = "resourceId")
    //@FieldRemark(column = "resource_id", field = "resourceId", name = "资源id")
    @Column(name = "resource_id")
    private String resourceId;

    /**
     * 用户名
     */
    @Transient
    private String username;

    /**
     * 文件名
     */
    @Transient
    private String fileName;

    public UdfFunc() {
    }

    public UdfFunc(String id, String funcName, String className, String projectId, Integer type, String argTypes,
                   String typeId, String remark, String resourceId) {
        this.id = id;
        this.funcName = funcName;
        this.className = className;
        this.projectId = projectId;
        this.type = type;
        this.argTypes = argTypes;
        this.typeId = typeId;
        this.remark = remark;
        this.resourceId = resourceId;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getFuncName() {
        return funcName;
    }

    public void setFuncName(String funcName) {
        this.funcName = funcName;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getProjectId() {
        return projectId;
    }

    public void setProjectId(String projectId) {
        this.projectId = projectId;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getArgTypes() {
        return argTypes;
    }

    public void setArgTypes(String argTypes) {
        this.argTypes = argTypes;
    }

    public String getTypeId() {
        return typeId;
    }

    public void setTypeId(String typeId) {
        this.typeId = typeId;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getResourceId() {
        return resourceId;
    }

    public void setResourceId(String resourceId) {
        this.resourceId = resourceId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    @Override
    public String getLogFormName() {
        if (avicit.platform6.commons.utils.StringUtils.isEmpty(super.logFormName)) {
            return "udf管理模块";
        } else {
            return super.logFormName;
        }
    }

    @Override
    public String getLogTitle() {
        if (avicit.platform6.commons.utils.StringUtils.isEmpty(super.logTitle)) {
            return "udf管理";
        } else {
            return super.logTitle;
        }
    }

    @Override
    public PlatformConstant.LogType getLogType() {
        if (super.logType == null) {
            return PlatformConstant.LogType.module_operate;
        } else {
            return super.logType;
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        UdfFunc udfFunc = (UdfFunc) o;
        return id.equals(udfFunc.id) &&
                Objects.equals(funcName, udfFunc.funcName) &&
                Objects.equals(className, udfFunc.className) &&
                Objects.equals(projectId, udfFunc.projectId) &&
                type == udfFunc.type &&
                Objects.equals(argTypes, udfFunc.argTypes) &&
                Objects.equals(typeId, udfFunc.typeId) &&
                Objects.equals(remark, udfFunc.remark) &&
                Objects.equals(resourceId, udfFunc.resourceId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, funcName, className, projectId, type, argTypes, typeId, remark, resourceId);
    }

    @Override
    public String toString() {
        return "UdfFunc{" +
                "id='" + id + '\'' +
                ", funcName='" + funcName + '\'' +
                ", className='" + className + '\'' +
                ", projectId='" + projectId + '\'' +
                ", type=" + type +
                ", argTypes='" + argTypes + '\'' +
                ", typeId='" + typeId + '\'' +
                ", remark='" + remark + '\'' +
                ", resourceId='" + resourceId + '\'' +
                '}';
    }
}
